<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<link rel="stylesheet" href="../js/bootstrap3/css/bootstrap.min.css">
<link rel="stylesheet" href="../js/bootstrap-table/bootstrap-table.min.css">
<link rel="stylesheet" href="../js/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css">
<link rel="stylesheet" href="../js/bootstrap-dialog/dist/css/bootstrap-dialog.min.css">
<script type="text/javascript" src="../js/jquery-3.6.0.min.js"></script>
<script type="text/javascript" src="../js/bootstrap3/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-table/bootstrap-table.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-table/locale/bootstrap-table-zh-CN.js"></script>
<script type="text/javascript" src="../js/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script type="text/javascript" src="../js/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script type="text/javascript" src="../js/bootstrap-bootbox/bootbox.js"></script>
<script type="text/javascript" src="../js/bootstrap-dialog/dist/js/bootstrap-dialog.min.js"></script>
<body>

<input type="hidden" id="queryId" th:value="${queryId}"/>
<div id="myTable"></div>

</body>
<script>

    $(function (){
        initTable();
    })

    function initTable(){

        $("#myTable").bootstrapTable({
            url:"../backstage/queryBuyerList?queryId="+$("#queryId").val(),
            pagination: true,               //是否显示分页（*）
            pageNumber:1,                   //初始化加载第一页，默认第一页
            pageSize: 3,                    //每页的记录行数（*）
            pageList: [3, 5, 7, 9],         //可供选择的每页的行数（*）
            method: 'get',                  //访问请求方式  get post
            smartDisplay: false,            //设置显示分页列表
            sidePagination: "server",       // 表格分页的是客户端分页还是服务端分页  cilent/server
            showRefresh:true,			    //是否显示刷新按钮
            showToggle:true,			    //是否显示详细视图和列表视图的切换按钮
            queryParams:function(){

                return {
                    page:this.pageNumber,
                    rows:this.pageSize

                }
            },

            columns: [{
                checkbox:true
            },{
                field:"buyerid",
                title:"编号"
            },{
                field: "buyername",
                title: "名称"
            },{
                field: "buyerphone",
                title: "电话"
            },{
                field: "buyerqianbao",
                title: "钱包"
            },{
                field: "status.statusname",
                title: "状态"
            },{
                field: "1",
                title: "操作",
                formatter:function(value,row,index){
                    if(row.status.statusid==1 || row.status.statusid==6){
                        return '<input type="button"  class="btn btn-sm btn-danger" onclick="updateStauts('+row.buyerid+','+row.status.statusid+')" value="删除">'
                            +  '<input type="button"  class="btn btn-sm btn-danger" onclick="openUpdateBuyer('+row.buyerid+')" value="修改">';
                    }
                    if(row.status.statusid==2 || row.status.statusid==7){
                        return '<input type="button"  class="btn btn-sm btn-info" onclick="updateStauts('+row.buyerid+','+row.status.statusid+')" value="恢复">';
                    }
                    if(row.status.statusid==5){
                        return '<input type="button"  class="btn btn-sm btn-success" onclick="updateStauts('+row.buyerid+','+6+')" value="通过">'
                            +  '<input type="button"  class="btn btn-sm btn-info" onclick="updateStauts('+row.buyerid+','+7+')" value="驳回">';
                    }
                }
            }]
        })
    }

    //删除状态
    function updateStauts(buyerid,status){
        $.ajax({
            url: "../backstage/updateBuyerStauts?buyerid="+buyerid+"&status="+status,
            type: "post",
            success:function (data){
                //alert("删除成功！");
                //location.href="../backstage/index";
                $("#myTable").bootstrapTable("refresh");
            },error:function(){
                alert("删除失败！");
            }
        })
    }

    /*
   修改开始
    */
    //打开修改浮动页面
    function openUpdateBuyer(buyerid){
        bootbox.dialog({
            size:"big",		//设置浮动页面大小 small-小	big-大
            title:"修改买家信息",
            message:createUpdateBuyer("../backstage/toUpdate?buyerid="+buyerid),
            closeButton:true,	//是否显示取消按钮，右上角的
            buttons:{
                'success':{
                    "label":"<i class='icon-ok'></i>提交",
                    "className":"btn-sm btn-success",
                    "callback":function(){
                        $.ajax({
                            url:"../backstage/updateBuyer",
                            type:"post",
                            data:$("#updateForm").serialize(),
                            success:function(data){
                                alert("恭喜你，修改成功！")
                                window.top.location.href="../backstage/index";
                                //$("#myTable").bootstrapTable("refresh");
                            },error:function(){
                                alert("修改失败！");
                            }
                        })
                    }
                },
                'cancle':{
                    "label":"<i class='icon-info'></i>取消",
                    "className":"btn-sm btn-danger",
                    "callback":function(){

                    }
                }
            }
        })
    }

    //创建修改页面
    var res;
    function createUpdateBuyer(url){
        $.ajax({
            url: url,
            async:false,
            success:function(data){
                res=data;
            }
        })
        return res;
    }
    /*
    修改结束
     */

</script>
</html>